/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/system/io
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AEStreamReader.h
// Author:		Gianluca Belardelli
// Date:		08/10/2013
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESTREAMREADER_H_
#define _AESTREAMREADER_H_

class AESeekAndTellStreamReader;

class AEStreamReader : public AEReferencedObject
{
// Methods
public:
	AE_DECLARE_CLASS_ALLOCATOR(TOBEDEFINED);

	AEStreamReader( void ) { }

	/// Read 'nbytes' into the buffer 'buf'.
	/// Return the number of characters read or zero for end of file.
	virtual int Read( void *lpBuf, AEINT32 nBytes ) = 0;

	/// Skip nbytes bytes of input.
	/// Return the actual number of bytes skipped.
	/// The default implementation uses read().
	virtual int Skip( AEINT32 nBytes ) { return -1; }

	/// Read at most n characters without changing the stream position.
	/// Returns the number of characters peeked.
	virtual int Peek( void *lpBuf, AEINT32 nBytes ) { return -1; }

	virtual AERESULT GetLastError( void ) const = 0;

	virtual class AESeekAndTellStreamReader *IsSeekTellSupported( void ) { return NULL; }
};


class AESeekAndTellStreamReader : public AEStreamReader
{
// Methods
public:
	AE_DECLARE_CLASS_ALLOCATOR(TOBEDEFINED);

	enum AESeekOptions
	{
		AESTREAM_SET=0,
		AESTREAM_CUR=1,
		AESTREAM_END=2
	};

	virtual AESeekAndTellStreamReader *IsSeekTellSupported( void ) { return this; }

	virtual AERESULT Seek( AEINT32 nOffset, AESeekOptions soOpt ) = 0;

	/// Get the current file offset if supported or -1 on error.
	virtual AEINT32 Tell( void ) const = 0;
};

#endif // _AESTREAMREADER_H_

